package com.dq.service.org.impl;

import com.dq.controller.in.OrgServiceProjectQuery;
import com.dq.domain.service.centre.OrgServiceProject;
import com.dq.exception.customException.AdminException;
import com.dq.repository.BaseRepositories;
import com.dq.service.org.OrgServiceProjectService;
import com.dq.vo.Vo;
import com.dq.vo.baseVo.VO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author luchangtong
 * @Date 2020/4/3 10:33
 */
@Service
public class OrgServiceProjectServiceImpl extends BaseRepositories implements OrgServiceProjectService {
    @Override
    public Vo list(OrgServiceProjectQuery orgServiceProjectQuery) throws AdminException {
        orgServiceProjectQuery.format();
        Map<String, Object> query = orgServiceProjectQuery.parseMap();
        if(orgServiceProjectQuery.getOrgId() != null){
            query.put("org_id",orgServiceProjectQuery.getOrgId());
            query.remove("orgId");
        }
        List<OrgServiceProject> list = dao.find(dao.query2Hql(OrgServiceProject.class, query), query);
        Long count = dao.count(dao.count2Hql(OrgServiceProject.class, query), query);
        PageHelper.startPage(orgServiceProjectQuery.getPage(), orgServiceProjectQuery.getSize());
        PageInfo pageInfo = new PageInfo((List<OrgServiceProject.Vo>) VO.toVOCollection(list));
        pageInfo.setTotal(count);
        return new Vo(pageInfo);
    }
}
